package cn.edu.ctbu.dp07.controller;

import cn.edu.ctbu.dp07.service.CourseService;
import cn.edu.ctbu.dp07.service.ScoreService;
import cn.edu.ctbu.dp07.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

    @Autowired
    private StudentService studentService;
    
    @Autowired
    private CourseService courseService;
    
    @Autowired
    private ScoreService scoreService;

    /**
     * 首页
     */
    @GetMapping("/")
    public String index(Model model) {
        // 统计学生数量
        long studentCount = studentService.findAll().size();
        // 统计课程数量
        long courseCount = courseService.findAll().size();
        // 统计成绩数量
        long scoreCount = scoreService.findAll().size();
        
        model.addAttribute("studentCount", studentCount);
        model.addAttribute("courseCount", courseCount);
        model.addAttribute("scoreCount", scoreCount);
        
        return "index";
    }
} 